##
## Makefile for cbin
##

TARGET := cbin
RESOURCES := data
RESHEADS := $(addsuffix .h,$(RESOURCES))
RESOBJS := $(addsuffix .res,$(RESOURCES))

RESDEP := $(filter-out $(RESOURCES),$(shell find $(RESOURCES) -printf '%p '))

#LIBS := -L/usr/X11R6/lib -lglut -lGLU -lGL -lXmu -lXext -lX11 -lm
LIBS := -lbfd
#OPTS := -O6 -ffast-math -mfpmath=sse -msse2
OPTS := -g

all: test

%.o: %.cpp
	g++ -c -o $@ $(OPTS) $(filter %.cpp,$^)

%.o: %.c
	g++ -c -o $@ $(OPTS) $(filter %.c,$^)

%: %.o
	g++ -o $@ $(OPTS) $^ $(LIBS)

%.res %.h: % cbin
	./cbin -v -o $*.res -P $*.h -dhave_ $(RESOURCES) $(RESOPTS)

$(TARGET): cbin.o

# use a namespace "testspace" and root descriptor "myroot"
RESOPTS := -n testspace -r myroot

# this uglyness rebuilds the resources whenever any file in $(RESOURCES) subdirectories change
$(RESOURCES): $(RESDEP)
	@echo "$< modified"
	touch $(RESOURCES)

linktest.o: $(RESHEADS)

linktest: linktest.o $(RESOBJS)

test: linktest
	./linktest

clean:
	-rm -f $(TARGET) cbin.o linktest linktest.o $(RESOBJS) $(RESHEADS)
